import axios from "axios"
import vue from "vue"

/** 路径 */
// const baseURL = 'http://127.0.0.1:7001'
// const baseURL = 'http://115.239.217.129:7001'
const baseURL = ''

export const instanceDefault = axios.create({
  baseURL:'',
})
const OAUTH_CLIENT_PC_TOKEN = ``

instanceDefault.defaults.timeout = 1000 * 60 * 10
// instanceDefault.defaults.headers.post["Content-Type"] = `application/x-www-form-urlencoded`

// 响应拦截器
instanceDefault.interceptors.response.use(
  (res) => {
    if (res) {
      // 只返回data
      return res.data
    }
  },
  (err) => {
    console.log(err.toString())
    return Promise.reject(err)
  }
)

export const apimap = () =>
  axios.get(`https://webapi.amap.com/maps?v=2.0&key=e79b404f5b25a89704095520699fc98f&plugin=Map3D,AMap.PolyEditor`)

// 创建新的俱乐部申请
export const apiA8Create = (body) =>
  instanceDefault.post(`/api/club-applications`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })



// 手动登录
export const apiLogin = (body) =>
  axios.post(`${baseURL}/api/person/login`, body, {
    headers: {
      Authorization: `Bearer ${OAUTH_CLIENT_PC_TOKEN}`,
    },
  })

// 修改密码
export const apiChangePassword = (body) =>
  instanceDefault.post(`/api/person/changePassword`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取部门列表
export const apiDepartmentList = () =>
  instanceDefault.post(`/api/department/list`, null, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 删除部门
export const apiDepartmentDelete = (body) =>
  instanceDefault.post(`/api/department/delete`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 更新部门
export const apiDepartmentUpdate = (body) =>
  instanceDefault.post(`/api/department/update`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 新增部门
export const apiDepartmentCreate = (body) =>
  instanceDefault.post(`/api/department/create`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取人员列表
export const apiPersonList = (body) =>
  instanceDefault.post(`/api/person/list`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 新增人员
export const apiPersonCreate = (body) =>
  instanceDefault.post(`/api/person/create`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 根据id获取人员信息
export const apiPersonGetById = (body) =>
  instanceDefault.post(`/api/person/getById`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 更新人员
export const apiPersonUpdate = (body) =>
  instanceDefault.post(`/api/person/update`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 更新人员启用状态
export const apiPersonUpdateActived = (body) =>
  instanceDefault.post(`/api/person/updateActived`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 重置密码
export const apiPersonResetPassword = (body) =>
  instanceDefault.post(`/api/person/resetPassword`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 删除人员
export const apiPersonDelete = (body) =>
  instanceDefault.post(`/api/person/delete`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取项目组列表
export const apiProjectGroupList = (body) =>
  instanceDefault.post(`/api/projectGroup/list`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取单个项目组
export const apiProjectGroupGetById = (body) =>
  instanceDefault.post(`/api/projectGroup/getById`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 创建项目组
export const apiProjectGroupCreate = (body) =>
  instanceDefault.post(`/api/projectGroup/create`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 更新项目组
export const apiProjectGroupUpdate = (body) =>
  instanceDefault.post(`/api/projectGroup/update`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 删除项目组
export const apiProjectGroupDelete = (body) =>
  instanceDefault.post(`/api/projectGroup/delete`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取人员所属的项目组列表
export const apiPersonProjectGroupGetGroups = (body) =>
  instanceDefault.post(`/api/personProjectGroup/getGroupsByPersonId`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取项目组的成员列表
export const apiPersonProjectGroupGetPersons = (body) =>
  instanceDefault.post(`/api/personProjectGroup/getPersonsByGroupId`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 添加人员到项目组
export const apiPersonProjectGroupAdd = (body) =>
  instanceDefault.post(`/api/personProjectGroup/addPersonToGroup`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 从项目除人员
export const apiPersonProjectGroupRemove = (body) =>
  instanceDefault.post(`/api/personProjectGroup/removePersonFromGroup`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取所有人员列表（不分页）
export const apiPersonGetAllList = (body) =>
  instanceDefault.post(`/api/person/getAllList`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取所有人员列表（不分页）树状
export const apiPersonGetAllListTree = (body) =>
  instanceDefault.post(`/api/person/getAllListTree`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取分组后的规则列表
export const apiScoringRuleGetGroupList = () =>
  instanceDefault.post(`/api/scoringRule/getGroupList`, null, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取单个规则
export const apiScoringRuleGetById = (body) =>
  instanceDefault.post(`/api/scoringRule/getById`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 创建规则
export const apiScoringRuleCreate = (body) =>
  instanceDefault.post(`/api/scoringRule/create`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 更新规则
export const apiScoringRuleUpdate = (body) =>
  instanceDefault.post(`/api/scoringRule/update`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 删除规则
export const apiScoringRuleDelete = (body) =>
  instanceDefault.post(`/api/scoringRule/delete`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 启用规则组
export const apiScoringRuleEnable = (body) =>
  instanceDefault.post(`/api/scoringRule/enable`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取当前启用的规则组
export const apiScoringRuleGetEnabled = () =>
  instanceDefault.post(`/api/scoringRule/getEnabled`, null, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取投稿列表
export const apiContributionList = (body) =>
  instanceDefault.post(`/api/contribution/list`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取单个投稿
export const apiContributionGetById = (body) =>
  instanceDefault.post(`/api/contribution/getById`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 创建投稿
export const apiContributionCreate = (body) =>
  instanceDefault.post(`/api/contribution/create`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 更新投稿
export const apiContributionUpdate = (body) =>
  instanceDefault.post(`/api/contribution/update`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 删除投稿
export const apiContributionDelete = (body) =>
  instanceDefault.post(`/api/contribution/delete`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 审核投稿
export const apiContributionApprove = (body) =>
  instanceDefault.post(`/api/contribution/approve`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 投稿打分
export const apiContributionScore = (body) =>
  instanceDefault.post(`/api/contribution/score`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 获取待处理平台数据列表
export const apiContributionGetPendingDataList = (body) =>
  instanceDefault.post('/api/contributionData/getPendingDataList', body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

/**
 * @description 导入平台数据
 */
export const apiContributionImportPlatformData = (body) =>
  instanceDefault.post('/api/contributionData/importPlatformData', body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

/**
 * @description 获取统计列表
 */
export const apiContributionGetStatsList = (body) =>
  instanceDefault.post('/api/contributionData/getStatsList', body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

/**
 * @description 获取个人统计数据
 */
export const apiPersonGetAllContributionStats = (body) =>
  instanceDefault.post('/api/person/getAllContributionStats', body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

/**
 * @description 获取概览数据
 */
export const apiContributionGetOverview = () =>
  instanceDefault.post('/api/contributionData/getOverview', null, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

/**
 * @description 获取投稿统计信息 根据部门
 */
export const apiGetAllContributionStatisticsByDepartment = (body) =>
  instanceDefault.post('/api/statistic/getAllContributionStatisticsByDepartment', body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

/**
 * @description 获取投稿统计信息 根据项目组
 */
export const apiGetAllContributionStatisticsByProjectGroup = (body) =>
  instanceDefault.post('/api/statistic/getAllContributionStatisticsByProjectGroup', body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

/** 人员去向表 */

// 手动登录
export const apiDestinationLogin = (body) =>
  axios.post(`${baseURL}/api/destination/login`, body, {
    headers: {
      Authorization: `Bearer ${OAUTH_CLIENT_PC_TOKEN}`,
    },
  })

// 获取人员去向表
export const apiDestinationGet = (body) =>
  instanceDefault.post(`/api/destination/getDestination`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 新增 / 更新 / 删除人员去向信息接口（统一处理）
export const apiDestinationHandle = (body) =>
  instanceDefault.post(`/api/destination/handle`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 查询 某人 某天 的去向
export const apiDestinationGetDestinationByPidAndDate = (body) =>
  instanceDefault.post(`/api/destination/getDestinationByPidAndDate`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 查询 某人 所有去向
export const apiDestinationGetDestinationByPid = (body) =>
  instanceDefault.post(`/api/destination/getDestinationByPid`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 查询 某人 所有投稿
export const apiDestinationGetAllContributionByPid = (body) =>
  instanceDefault.post(`/api/destination/getAllContributionByPid`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 查询 日志
export const apiGetLogs = (body) =>
  instanceDefault.post(`/api/logs`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 创建用车申请
export const apiVehicleApplicationCreate = (body) =>
  instanceDefault.post(`/api/vehicle-application/create`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 用车申请列表
export const apiVehicleApplicationList = (body) =>
  instanceDefault.post(`/api/vehicle-application/list`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 查询可用车辆信息
export const apiVehicleApplicationAvailableVehicles = (body) =>
  instanceDefault.post(`/api/vehicle-application/available-vehicles`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 查询可用驾驶员信息
export const apiVehicleApplicationAvailableDrivers = (body) =>
  instanceDefault.post(`/api/vehicle-application/available-drivers`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 根据id查询所有关于申请单的信息
export const apiVehicleApplicationDetailById = (body) =>
  instanceDefault.post(`/api/vehicle-application/details`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 取消用车申请
export const apiVehicleApplicationCancel = (body) =>
  instanceDefault.post(`/api/vehicle-application/cancel`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 审核用车申请
export const apiVehicleApplicationReview = (body) =>
  instanceDefault.post(`/api/vehicle-application/review`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 根据车辆 ID 获取分配给该车辆的所有申请单信息
export const apiVehicleApplicationByVehicle = (body) =>
  instanceDefault.post(`/api/vehicle-application/applications-by-vehicle`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 根据驾驶员 ID 获取分配给该驾驶员的所有申请单信息
export const apiVehicleApplicationByDriver = (body) =>
  instanceDefault.post(`/api/vehicle-application/applications-by-driver`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 根据YYYY-MM获取日常记录
export const apiVehicleApplicationDailyRecords = (body) =>
  instanceDefault.post(`/api/vehicle/daily-records`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  })

// 新增车辆每日记录
export const apiCreateVehicleDailyRecord = (body) =>
  instanceDefault.post(`/api/vehicle-application/create-daily-record`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 编辑车辆每日记录
export const apiUpdateVehicleDailyRecord = (body) =>
  instanceDefault.post(`/api/vehicle-application/update-daily-record`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 删除车辆每日记录
export const apiDeleteVehicleDailyRecord = (body) =>
  instanceDefault.post(`/api/vehicle-application/delete-daily-record`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 车辆数据统计
export const apiVehicleStatisticsDateRange = (body) =>
  instanceDefault.post(`/api/vehicle-statistics/date-range`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 审批统计接口 主页
export const apiApprovalGetStatistics = (body) =>
  instanceDefault.post(`/api/approval/getStatistics`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 发起审批审批
export const apiApprovalCreate = (body) =>
  instanceDefault.post(`/api/approval/create`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 获取审批列表
export const apiApprovalList = (body) =>
  instanceDefault.post(`/api/approval/list`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 获取单个审批详情
export const apiApprovalGetById = (body) =>
  instanceDefault.post(`/api/approval/getById`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 获取用户已审批列表
export const apiApprovalGetApprovedList = (body) =>
  instanceDefault.post(`/api/approval/getApprovedList`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 获取用户待审批列表
export const apiApprovalGetPendingList = (body) =>
  instanceDefault.post(`/api/approval/getPendingList`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 处理审批
export const apiApprovalHandle = (body) =>
  instanceDefault.post(`/api/approval/handle`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 获取用户发起的审批列表
export const apiApprovalGetMyApplications = (body) =>
  instanceDefault.post(`/api/approval/getMyApplications`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 撤回审批
export const apiApprovalWithdraw = (body) =>
  instanceDefault.post(`/api/approval/withdraw`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 审批权限人员获取
export const apiGetPersonnelWithPermissions = (body) =>
  instanceDefault.post(`/api/approvalPermission/getPersonnelWithPermissions`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 审批权限人员更新
export const apiUpdatePersonApprovalPermissions = (body) =>
  instanceDefault.post(`/api/approvalPermission/updatePersonApprovalPermissions`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 根据审批级别获取人员树状结构
export const apiFindApproversByLevelTree = (body) =>
  instanceDefault.post(`/api/approvalPermission/findApproversByLevelTree`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 与我有关的审批（申请人和工作成员）
export const apiGetApplicationsByPerson = (body) =>
  instanceDefault.post(`/api/approval/getApplicationsByPerson`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });

// 更新产出记录
export const apiApprovalUpdateOutput = (body) =>
  instanceDefault.post(`/api/approval/updateOutput`, body, {
    headers: {
      Authorization: `Bearer ${window.sessionStorage.getItem('token')}`
    }
  });